package kr.hkit.androidcomplete01.ch06.work;

import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Shader.TileMode;
import android.os.Bundle;
import android.view.View;

public class ShaderGradient extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(new MyView(this));
	}
	
	class MyView extends View{
		
		private Paint paint;
		
		public MyView(Context context){
			super(context);
			paint = new Paint();
	}
		@Override
		protected void onDraw(Canvas canvas) {
			super.onDraw(canvas);
			
			canvas.drawColor(Color.LTGRAY);
			paint.setAntiAlias(true);
			
			int[] colors = { Color.RED, Color.GREEN, Color.BLUE, Color.YELLOW, Color.WHITE};
			float[] pos = { 0.0f, 0.1f, 0.6f, 0.9f, 1.0f};
			//수평
			paint.setShader(new LinearGradient(0, 0, 100, 0, Color.BLUE, Color.WHITE, TileMode.CLAMP));
			canvas.drawRect(0, 0, 100, 100, paint);
			//우하향
			paint.setShader(new LinearGradient(110, 0, 210, 100, Color.BLUE, Color.WHITE, TileMode.CLAMP));
			canvas.drawRect(110, 0, 210, 100, paint);
			//우상향
			paint.setShader(new LinearGradient(220, 100, 320, 0, Color.BLUE, Color.WHITE, TileMode.CLAMP));
			canvas.drawRect(220, 0, 320, 100, paint);
			//가장자리 반복
			paint.setShader(new LinearGradient(0, 0, 100, 0, Color.BLUE, Color.WHITE, TileMode.CLAMP));
			canvas.drawRect(0, 110, 320, 150, paint);
			//무늬반복
			paint.setShader(new LinearGradient(0, 0, 100, 0, Color.BLUE, Color.WHITE, TileMode.REPEAT));
			canvas.drawRect(0, 160, 320, 200, paint);
			//무늬 반사 반복
			paint.setShader(new LinearGradient(0, 0, 100, 0, Color.BLUE, Color.WHITE, TileMode.MIRROR));
			canvas.drawRect(0, 210, 320, 250, paint);
			//여러 가지 색상 균등 배치
			paint.setShader(new LinearGradient(0, 0, 320, 0, colors, null, TileMode.CLAMP));
			canvas.drawRect(0, 260, 320, 300, paint);
			//여러 가지 색상 임의 배치
			paint.setShader(new LinearGradient(0, 0, 320, 0, colors, pos, TileMode.CLAMP));
			canvas.drawRect(0, 310, 320, 350, paint);
			
			
			
			
			
		}
		
		
	}
}
